import datetime
import sys


def calender(month,year):
    if (0<month<3):
        m=int(month+12)
        y=int((year-1)%100)
        c=int((year-1)%100)
    else:
        y=int(year%100)
        c=int(year//100)
        m=month
   
    all=26*(m+1)/10
    w=y+int(y/4)+int(c/4)-2*c+int(all)
    return w%7


def display(month):
    list1=['Jan','Feb','Mar','Apr','May','June'
    ,'July','Aug','Sep','Oct','Nov'
    ,'Dec']
    return list1[month-1]


def get_days(year,month):
    days_of_month=[
     0,31,28,31,30,31,30,31,31,30,31,30,31
    ]
    days=days_of_month[month]
    return days+1 if is_leap(year) and month==2 else days


def is_leap(year):
    return(year%4==0 and year%100!=0) or year%400==0



def main():
    if len(sys.argv)==3:
        month=int(sys.argv[1])
        year=int(sys.argv[2])
        
        
        
        
    else:
        curr_date=datetime.datetime.now()
        year=curr_date.year
        day=curr_date.day
        month=curr_date.month
    print(f'{display(month)} {year}'.center(20))
    print('Su Mo Tu We Th Fr Sa')
    week=calender(month,year)
    print(' '*3*week,end='')
    days=get_days(year,month)
    for day in range(1,days+1):
        print(f'{day}'.rjust(2),end=' ')
        week+=1
        if week==7:
            print()
            week=0
    print()

if __name__=='__main__':
    main()
